import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author John Skinner
 *
 */
public class GeoApp extends javax.swing.JDialog {

    DrawPanel m_drawPanel;

    /**
     * Creates new form GeoApp
     */
    static GeoApp m_instance;

    public GeoApp(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        m_drawPanel = new DrawPanel();
        m_drawPanel.setBackground(Color.white);
        m_drawPanel.setForeground(Color.BLACK);
        BorderLayout bl = new BorderLayout();
        m_drawRegion.setLayout(bl);
        m_drawRegion.add(m_drawPanel);
        bl.addLayoutComponent(m_drawPanel, BorderLayout.CENTER);
        m_drawPanel.setPreferredSize(new Dimension(400,400));
        m_drawPanel.setMinimumSize(new Dimension(90,90));
        m_drawPanel.setVisible(true);
        m_instance = this;
        invalidate();
        pack();

    }

    public GeoApp instance() {
        return m_instance;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        m_controlRegion = new javax.swing.JPanel();
        m_addTriangle = new javax.swing.JButton();
        m_addCross = new javax.swing.JButton();
        m_drawRegion = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        m_addTriangle.setText("Add Triangle");
        m_addTriangle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_addTriangleActionPerformed(evt);
            }
        });

        m_addCross.setText("Add Cross");
        m_addCross.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_addCrossActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout m_controlRegionLayout = new javax.swing.GroupLayout(m_controlRegion);
        m_controlRegion.setLayout(m_controlRegionLayout);
        m_controlRegionLayout.setHorizontalGroup(
            m_controlRegionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(m_controlRegionLayout.createSequentialGroup()
                .addGroup(m_controlRegionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(m_addTriangle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(m_addCross, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 27, Short.MAX_VALUE))
        );
        m_controlRegionLayout.setVerticalGroup(
            m_controlRegionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(m_controlRegionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(m_addTriangle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(m_addCross)
                .addContainerGap(288, Short.MAX_VALUE))
        );

        m_drawRegion.setBackground(java.awt.Color.white);

        javax.swing.GroupLayout m_drawRegionLayout = new javax.swing.GroupLayout(m_drawRegion);
        m_drawRegion.setLayout(m_drawRegionLayout);
        m_drawRegionLayout.setHorizontalGroup(
            m_drawRegionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 372, Short.MAX_VALUE)
        );
        m_drawRegionLayout.setVerticalGroup(
            m_drawRegionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(m_controlRegion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(m_drawRegion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(m_drawRegion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(m_controlRegion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void m_addTriangleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_addTriangleActionPerformed
        GeoApp ga = instance();
        Triangle t = new Triangle();
        ga.m_drawPanel.addDrawable(t);
        

    }//GEN-LAST:event_m_addTriangleActionPerformed

    private void m_addCrossActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_addCrossActionPerformed
        GeoApp ga = instance();
        Cross t = new Cross();
        ga.m_drawPanel.addDrawable(t);
    }//GEN-LAST:event_m_addCrossActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GeoApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GeoApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GeoApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GeoApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GeoApp dialog = new GeoApp(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton m_addCross;
    private javax.swing.JButton m_addTriangle;
    private javax.swing.JPanel m_controlRegion;
    private javax.swing.JPanel m_drawRegion;
    // End of variables declaration//GEN-END:variables
}
